package com.newhopegroup.webcommons.jsonbody;

import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

import java.io.Serializable;

/**
 * Created by wangshida on 15/7/1.
 * JSON返回结果顶层结构
 */
public class JsonResult implements Serializable {
    private Boolean result;
    private String msg;
    private Object data;

    public JsonResult() {
        result = true;
        msg = "";
        data = null;
    }

    public JsonResult(Object data) {
        result = true;
        msg = "";
        this.data = data;
    }

    public static JsonResult build(Object data) {
        return new JsonResult(data);
    }

    public JsonResult(Boolean result, String msg, Object data) {
        this.result = ObjectUtils.defaultIfNull(result, false);
        this.msg = ObjectUtils.defaultIfNull(msg, "");
        this.data = data;
    }

    public static JsonResult build(Boolean result, String msg, Object data) {
        return new JsonResult(result, msg, data);
    }

    public Boolean isResult() {
        return result;
    }

    public void setResult(Boolean result) {
        this.result = result;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return ReflectionToStringBuilder.toString(this);

    }
}
